package com.yu.waterstation.system.modules.app.controller;

import com.yu.waterstation.common.common.annotation.AdminLog;
import com.yu.waterstation.common.common.annotation.NeedPermission;
import com.yu.waterstation.common.common.exception.ServiceException;
import com.yu.waterstation.common.common.util.result.Result;
import com.yu.waterstation.common.entity.app.Worker;
import com.yu.waterstation.system.modules.app.service.impl.WorkerServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * date 2020-12-02 18:16:20
 */
@Api(tags = "系统：送水员管理")
@RestController
@RequestMapping("system/worker")
public class WorkerController {

    @Resource
    private WorkerServiceImpl workerService;

    @ApiOperation("查询全部")
    @NeedPermission("system:worker:list")
    @GetMapping("/list")
    public Result getAllWorkers() throws ServiceException {
        return Result.ok(workerService.getAllWorkers());
    }

    @ApiOperation("增加")
    @AdminLog
    @NeedPermission("system:worker:add")
    @PostMapping("")
    public Result add(@RequestBody Worker worker) throws Exception {
        return Result.ok(workerService.addWorker(worker));
    }

    @ApiOperation("批量删除")
    @AdminLog
    @NeedPermission("system:worker:delete")
    @DeleteMapping("/batch")
    public Result delete(@RequestBody List<Integer> idList) throws ServiceException {
        return Result.ok(workerService.deleteWorkerBatchIds(idList));
    }

    @ApiOperation("修改")
    @AdminLog
    @NeedPermission("system:worker:update")
    @PutMapping("")
    public Result update(@RequestBody Worker worker) throws Exception {
        return Result.ok(workerService.updateWorker(worker));
    }


    @ApiOperation("冻结|激活账号")
    @AdminLog
    @NeedPermission("system:student:update")
    @PutMapping("/status/{workerId}")
    public Result updateWorkerStatus(@PathVariable Integer workerId) throws ServiceException {
        return Result.ok(workerService.updateWorkerStatus(workerId));
    }

    @ApiOperation("重置密码")
    @AdminLog
    @NeedPermission("system:worker:update")
    @PutMapping("/resetPassword/{workerId}")
    public Result update(@PathVariable Integer workerId) throws Exception {
        return Result.ok(workerService.resetPassword(workerId));
    }
}
